from sqlalchemy import Column, Integer, String, Text, DateTime, JSON,BigInteger
from sqlalchemy.sql import func
from db.database import Base
from utils.snowflake import snowflake
# from pysnowflake import snowflake  # 导入雪花生成器

class Comment(Base):
    __tablename__ = "comments"

    # 组件自增id 使用雪花算法
    # id = Column(String(36), primary_key=True, default=lambda: str(uuid.uuid4()))
    id = Column(BigInteger, primary_key=True, default=snowflake.next_id)
    content = Column(Text, nullable=False)
    user_id = Column(Integer,  nullable=True )
    username = Column(String(50), nullable=False)
    type = Column(String(20), nullable=True)
    created_at = Column(DateTime(timezone=True), server_default=func.now())
    post_id = Column(Integer,  nullable=True )
    parent_id = Column(Integer,  nullable=True )
    status = Column(String(50), nullable=False)
    updated_at = Column(DateTime(timezone=True), server_default=func.now())
    deleted_at = Column(DateTime(timezone=True), nullable=True, default=None)
    # extradata 为关键字，加名称映射到数据库的字段
    extradata = Column('extradata',JSON, nullable=True, default=None)
